﻿using System;

namespace ABC.Core.Extentions
{
    public static class DateTimeExtention
    {
        public static string ToFriendlyDate(this DateTime value)
        {
            return value.ToString("dd MMMM yyyy");
        }
        public static string ToShortDate(this DateTime value)
        {
            return value.ToString("dd MMM yyyy");
        }
        public static string ToRelativeDate(this DateTime value)
        {
            return value.Date == DateTime.Today
                       ? "Сегодня"
                       : (value.AddDays(1).Date == DateTime.Today
                              ? "Вчера"
                              : (value.AddDays(2).Date == DateTime.Today
                                     ? "Позавчера"
                                     : (value.AddDays(-1).Date == DateTime.Today
                                            ? "Завтра"
                                            : (value.AddDays(-2).Date == DateTime.Today
                                                   ? "Послезавтра"
                                                   : value.ToString("dddd, dd MMMM")))));
        }
        public static string GetFullAge(this DateTime value)
        {
            var age = DateTime.Now.Year - value.Year;

            if (age == 0 || age < 0)
            {
                return age.ToString();
            }

            if (DateTime.Now.Month > value.Month)
            {
                return age.ToString();
            }

            if (DateTime.Now.Month == value.Month && DateTime.Now.Day >= value.Day)
            {
                return age.ToString();
            }

            return (age - 1).ToString();
        }

        public static string GetAgeCase(int age)
        {
            if (age >= 5 && age <= 14)
                return "полных лет";

            var num = age - (int)(Math.Floor((double)age / 10) * 10);

            if (num == 1)
                return "полный год";

            if (num == 0)
                return "полных лет";

            if (num >= 2 && num <= 4)
                return "полных года";

            if (num >= 5 && num <= 9)
                return "полных лет";

            return string.Empty;
        }
        public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
        {
            // Unix timestamp is seconds past epoch
            var dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
            return dtDateTime;
        }

    }
}
